home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / pwd / c / getpwuid < prev    next >
Text File  |  1996-11-09  |  1KB  |  44 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/pwd/c/RCS/getpwuid,v $
  4.  * $Date: 1996/10/30 22:04:51 $
  5.  * $Revision: 1.1 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: getpwuid,v $
  10.  * Revision 1.1  1996/10/30 22:04:51  unixlib
  11.  * Initial revision
  12.  *
  13.  ***************************************************************************/
  14.  
  15. static const char rcs_id[] = "$Id: getpwuid,v 1.1 1996/10/30 22:04:51 unixlib Rel $";
  16.  
  17. /* pwd.c.getpwuid. Search for an entry with a matching user ID.
  18.  
  19.    This is a POSIX.1 function written by Nick Burrett, 13 October 1996.  */
  20.  
  21. #include <stddef.h>
  22. #include <stdio.h>
  23. #include <pwd.h>
  24. #include <sys/types.h>
  25.  
  26. /* Search for an entry with a matching uid.  */
  27. struct passwd *
  28. getpwuid (uid_t uid)
  29. {
  30.   FILE *stream;
  31.   struct passwd *p;
  32.  
  33.   stream = fopen ("/etc/passwd", "r");
  34.   if (stream == NULL)
  35.     return NULL;
  36.  
  37.   while ((p = fgetpwent(stream)) != NULL)
  38.     if (p->pw_uid == uid)
  39.       break;
  40.  
  41.   fclose(stream);
  42.   return p;
  43. }
  44.